<?php
// 获取数据库数据
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");

//查询每种类型的商品数量
$sql_1 = "SELECT g_type, COUNT(*) AS g_count FROM tb_goods_info GROUP BY g_type";

//查询用户数量
$sql_2 = "SELECT ustatus, COUNT(*) AS u_count FROM tb_user_info GROUP BY ustatus ORDER BY ustatus DESC";

//查询近7天留言数量
$sql_3 = "SELECT 
    DATE(r_date) AS message_date, 
    COUNT(*) AS message_count
FROM 
    tb_remark_info
WHERE 
    r_date >= DATE_SUB(CURDATE(), INTERVAL 6 DAY) AND 
    r_date < CURDATE() + INTERVAL 1 DAY
GROUP BY 
    DATE(r_date)
ORDER BY 
    DATE(r_date)";

if($_GET['type'] == '1'){
    $result_1 = mysqli_query($conn, $sql_1);
    $json_data_1 = array();
    while($row = mysqli_fetch_assoc($result_1)){
        $json_data_1[] = $row;
    }
    //将查询结果转换为json格式
    echo json_encode($json_data_1);
}else if($_GET['type'] == '2'){
    $result_2 = mysqli_query($conn, $sql_2);
    $json_data_2 = array();
    while($row = mysqli_fetch_assoc($result_2)){
        $json_data_2[] = $row;
    }
    //将查询结果转换为json格式
    echo json_encode($json_data_2);
}else if($_GET['type'] == '3'){
    $result_3 = mysqli_query($conn, $sql_3);
    $json_data_3 = array();
    while($row = mysqli_fetch_assoc($result_3)){
        $json_data_3[] = $row;
    }
    echo json_encode($json_data_3);
}

